package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.BoxItem;
import com.sc.nft.entity.MallOrder;
import com.sc.nft.entity.MallPayOrderItem;
import com.sc.nft.mapper.MallPayOrderItemMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.dao
 * @Project：sc_metago
 * @name：MallPayOrderItemDao
 * @Date：2024/5/13 17:22
 * @Filename：MallPayOrderItemDao
 */
@Slf4j
@Repository
public class MallPayOrderItemDao extends ServiceImpl<MallPayOrderItemMapper, MallPayOrderItem> {

    /**
     * 小程序商城订单与支付单关联表
     *
     * @param orderId
     * @return
     */
    public MallPayOrderItem getMallPayOrderItemByOrderId(Long orderId) {
        LambdaQueryWrapper<MallPayOrderItem> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallPayOrderItem::getOrderId, orderId);
        wrapper.orderByDesc(MallPayOrderItem::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    /**
     * 小程序商城订单与支付单关联表
     *
     * @param orderIds
     * @return
     */
    public List<MallPayOrderItem> getMallPayOrderItemByOrderIds(List<Long> orderIds) {
        LambdaQueryWrapper<MallPayOrderItem> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(MallPayOrderItem::getOrderId, orderIds);
        return list(wrapper);
    }

    /**
     * 移除
     *
     * @param orderId
     */
    public Boolean removeMallPayOrderItem(Long orderId) {
        LambdaUpdateWrapper<MallPayOrderItem> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MallPayOrderItem::getOrderId, orderId);
        return remove(wrapper);
    }

    /**
     * 移除
     *
     * @param orderIds
     */
    public Boolean removeMallPayOrderItem(List<Long> orderIds) {
        LambdaUpdateWrapper<MallPayOrderItem> wrapper = new LambdaUpdateWrapper<>();
        wrapper.in(MallPayOrderItem::getOrderId, orderIds);
        return remove(wrapper);
    }

    /**
     * 根据支付单ID获取订单列表
     *
     * @param payOrderId
     * @return
     */
    public List<MallOrder> getOrderListByPayOrderId(Long payOrderId) {
        return baseMapper.getOrderListByPayOrderId(payOrderId);
    }
}
